package org.springblade.modules.material.strategy.impl;

import org.springblade.common.enums.library.QuestionType;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.modules.library.vo.QuestionOptionVO;
import org.springblade.modules.material.entity.PaperAnswerEntity;
import org.springblade.modules.material.entity.PaperAnswerOptionEntity;
import org.springblade.modules.library.entity.QuestionOptionEntity;
import org.springblade.modules.material.strategy.CalculateScoreStrategy;
import org.springblade.modules.material.vo.PaperAnswerOptionVO;
import org.springblade.modules.material.vo.PaperAnswerVO;
import org.springblade.modules.material.vo.PaperDetailsRelatedVO;
import org.springblade.modules.material.vo.PaperReleaseDetailVO;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @Author: 俊鑫
 * @Description: 计算单选题分数
 */
public class CalculateSingleChoice implements CalculateScoreStrategy {

	@Override
	public Integer calculateScore(List<PaperReleaseDetailVO> paperReleaseDetailVOList,
								  List<PaperAnswerOptionEntity> paperAnswerOptionEntityList,Long  paperAnswerId,Integer multipleScoreSetting) {
		int score=0;
		for (PaperReleaseDetailVO paperReleaseDetailVO:paperReleaseDetailVOList){
			//选项内容
			List<QuestionOptionVO> questionOptionList = paperReleaseDetailVO.getQuestionOptionList();
			for (QuestionOptionVO questionOptionVO:questionOptionList){
				if (questionOptionVO.getChoice()==1){
					PaperAnswerOptionEntity paperAnswerOptionEntity=new PaperAnswerOptionEntity();
					paperAnswerOptionEntity.setAnswerId(paperAnswerId);
					paperAnswerOptionEntity.setUserId(AuthUtil.getUserId());
					paperAnswerOptionEntity.setChecked(questionOptionVO.getId());
					paperAnswerOptionEntity.setReleaseDetailId(paperReleaseDetailVO.getId());
					paperAnswerOptionEntity.setValue(0);
					paperAnswerOptionEntity.setQuestionId(questionOptionVO.getQuestionBankId());
					if (questionOptionVO.getIsRight()==1 ) {
						score+=paperReleaseDetailVO.getValue();
						paperAnswerOptionEntity.setValue(paperReleaseDetailVO.getValue());
					}
					paperAnswerOptionEntity.setQuestionType(QuestionType.SINGLE.getCode());
					paperAnswerOptionEntityList.add(paperAnswerOptionEntity);
					break; //单选题可以直接结束
				}
			}
		}


		return score;
	}
}
